home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 17.2 KB | 515 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWIntrng.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWINTRNG_H
- #include "FWIntrng.h"
- #endif
-
- #ifndef FWPROXY_H
- #include "FWProxy.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWPXYFRM_H
- #include "FWPxyFrm.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWCONTNG_H
- #include "FWContng.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- OD Utils -----
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include "WinStat.xh"
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include "ODCtr.xh"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fw_embedding2
- #endif
-
- //========================================================================================
- // class FW_CEmbeddingDataInterchange
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange constructor
- //----------------------------------------------------------------------------------------
- FW_CEmbeddingDataInterchange::FW_CEmbeddingDataInterchange(Environment* ev, FW_CEmbeddingPart* part) :
- FW_CDataInterchange(ev, part)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange destructor
- //----------------------------------------------------------------------------------------
- FW_CEmbeddingDataInterchange::~FW_CEmbeddingDataInterchange()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::DoExternalizeSingleEmbeddedFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingDataInterchange::DoExternalizeSingleEmbeddedFrame(Environment* ev,
- ODFrame* odEmbeddedFrame,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- destinationSU->AddProperty(ev, kODPropContentFrame);
- destinationSU->AddValue(ev, kODWeakStorageUnitRef);
-
- // Add the cloneKind property and value
- destinationSU->AddProperty(ev, kODPropCloneKindUsed)->AddValue(ev, kODCloneKind);
- ODCloneKind cloneKind = cloneInfo->GetCloneKind(ev);
- FW_CByteArray byteArray(&cloneKind, sizeof(ODCloneKind));
- destinationSU->SetValue(ev, byteArray);
-
- // Clone the embedded part into the root storage unit.
- FW_CAcquiredODPart aqPart = odEmbeddedFrame->AcquirePart(ev);
- ODID toRootID = cloneInfo->Clone(ev, aqPart->GetID(ev), destinationSU->GetID(ev), odEmbeddedFrame->GetID(ev));
-
- // Clone the embedded frame to any storage unit. Must be done
- // after cloning the part because it strongly references the part
- ODID toFrameID = cloneInfo->Clone(ev, odEmbeddedFrame->GetID(ev), 0, odEmbeddedFrame->GetID(ev));
-
- // Weakly reference the frame
- destinationSU->Focus(ev, kODPropContentFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
- ODStorageUnitRef aSURef;
- destinationSU->GetWeakStorageUnitRef(ev, toFrameID, aSURef);
- byteArray.Set(&aSURef, sizeof(ODStorageUnitRef));
- destinationSU->SetValue(ev, byteArray);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::DoInternalizeSingleEmbeddedFrame
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CEmbeddingDataInterchange::DoInternalizeSingleEmbeddedFrame(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- ODDraft* myDraft = fPart->GetDraft(ev);
-
- cloneInfo->fClonedPartID = cloneInfo->Clone(ev, sourceSU->GetID(ev), 0, 0);
- FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
-
- result = FW_kInternalizePart;
-
- // ----- Try Cloning the frame -----
- ODStorageUnitRef aSURef;
- sourceSU->Focus(ev, kODPropContentFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
-
- FW_CByteArray byteArray;
- sourceSU->GetValue(ev, sizeof(aSURef), byteArray);
- byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
-
- if (sourceSU->IsValidStorageUnitRef(ev, aSURef))
- {
- ODID sourceFrameID = sourceSU->GetIDFromStorageUnitRef(ev, aSURef);
- cloneInfo->fClonedFrameID = cloneInfo->Clone(ev, sourceFrameID, 0, 0);
- FW_ASSERT(cloneInfo->fClonedFrameID != kODNULLID);
-
- result = FW_kInternalizeFrame;
- }
- else
- {
- // ----- Look for the frame shape -----
- cloneInfo->fFrameShape = PrivReadFrameShape(ev, sourceSU);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivHandleExternalizeData
- //----------------------------------------------------------------------------------------
- // Here we have two cases:
- // 1) The data consists of only one embedded part(frame). In this case
- // we just want to clone it into the storage unit.
- // 2) The data is two or more embedded parts or one or more
- // embedded parts plus content. In this case we externalize the data.
-
- void FW_CEmbeddingDataInterchange::PrivHandleExternalizeData(Environment* ev,
- FW_CContent* content,
- ODStorageUnit* destinationSU,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_ASSERT(cloneInfo->GetScopeFrame(ev));
- FW_ASSERT(FW_DYNAMIC_CAST(FW_CEmbeddingContent, content) != NULL);
-
- FW_MProxy* singleProxy = content ? ((FW_CEmbeddingContent*)content)->IsDataOnlyOneProxy(ev) : NULL;
- if (singleProxy) // if the data is only one embedded frame clone it into the SU
- {
- FW_CEmbeddingFrame* embeddingFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
- FW_ASSERT(embeddingFrame);
-
- FW_CAcquiredODFrame aqEmbeddedFrame = singleProxy->AcquireEmbeddedFrame(ev, embeddingFrame);
- FW_ASSERT(aqEmbeddedFrame != NULL);
-
- DoExternalizeSingleEmbeddedFrame(ev, aqEmbeddedFrame, destinationSU, cloneInfo);
-
- }
- else
- {
- FW_CDataInterchange::PrivHandleExternalizeData(ev, content, destinationSU, storageKind, cloneInfo);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivHandleInternalizeData
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CEmbeddingDataInterchange::PrivHandleInternalizeData(Environment* ev,
- FW_CContent* content,
- ODStorageUnit* sourceSU,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_ASSERT(FW_DYNAMIC_CAST(FW_CEmbeddingContent, content) != NULL);
-
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- // ----- Test first if the data consists of a single embedded frame
- if (sourceSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
- {
- result = DoInternalizeSingleEmbeddedFrame(ev, sourceSU, cloneInfo);
- }
- else
- {
- // ----- Try to incorporate -----
- result = FW_CDataInterchange::PrivHandleInternalizeData(ev, content, sourceSU, storageKind, cloneInfo);
-
- // ----- Then try embedding -----
- if (result == FW_kInternalizeFailed)
- result = PrivClonePart(ev, sourceSU, cloneInfo);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivPostInternalizeData
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingDataInterchange::PrivPostInternalizeData(Environment* ev,
- FW_CContent* content,
- FW_CCloneInfo* cloneInfo,
- FW_EInternalizeResult result)
- {
- FW_ASSERT(FW_DYNAMIC_CAST(FW_CEmbeddingContent, content) != NULL);
-
- switch (result)
- {
- case FW_kInternalizeFailed:
- FW_DEBUG_MESSAGE("PrivPostInternalizeData should not have been called");
- break;
-
- case FW_kInternalizeContent:
- if (cloneInfo->fClonedProxyList != NULL) // No embedded frames have been read
- PrivPostInternalizeContent(ev, cloneInfo);
- break;
-
- case FW_kInternalizePart:
- PrivPostInternalizePart(ev, (FW_CEmbeddingContent*)content, cloneInfo, GetPresentation(ev, cloneInfo)->GetDefaultEmbeddedFrameViewType(ev));
- break;
-
- case FW_kInternalizeFrame:
- PrivPostInternalizeFrame(ev, (FW_CEmbeddingContent*)content, cloneInfo, GetPresentation(ev, cloneInfo)->GetDefaultEmbeddedFrameViewType(ev));
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivReadFrameShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CEmbeddingDataInterchange::PrivReadFrameShape(Environment* ev, ODStorageUnit* sourceSU)
- {
- // ----- Look for a frame shape property -----
- ODShape* frameShape = NULL;
-
- if (sourceSU->Exists(ev, kODPropSuggestedFrameShape, (ODValueType)NULL, 0))
- {
- // ----- Note: we focus on the property, ReadShape will focus on the value
- sourceSU->Focus(ev, kODPropSuggestedFrameShape,
- kODPosUndefined,
- (ODValueType)NULL,
- (ODValueIndex)1,
- kODPosUndefined);
-
- frameShape = ::FW_NewODShape(ev);
- frameShape = frameShape->ReadShape(ev, sourceSU);
- }
-
- return frameShape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivPostInternalizeContent
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingDataInterchange::PrivPostInternalizeContent(Environment* ev, FW_CCloneInfo* cloneInfo)
- {
- FW_TOrderedCollectionIterator<FW_MProxy> ite(cloneInfo->fClonedProxyList);
- for (FW_MProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
- {
- proxy->PrivPostClone(ev, cloneInfo);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivPostInternalizeFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingDataInterchange::PrivPostInternalizeFrame(Environment* ev,
- FW_CEmbeddingContent* content,
- FW_CCloneInfo* cloneInfo,
- ODTypeToken viewAs)
- {
- FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
- FW_ASSERT(cloneInfo->fClonedFrameID != kODNULLID);
-
- FW_CEmbeddingFrame* embeddingScopeFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
- FW_ASSERT(embeddingScopeFrame);
-
- // ----- Get the part -----
- // ODDraft* myDraft = fPart->GetDraft(ev);
- // FW_CAcquiredODPart aqNewPart = myDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
- ODDraft* toDraft = cloneInfo->GetToDraft(ev);
- FW_CAcquiredODPart aqNewPart = toDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
- FW_ASSERT(aqNewPart != NULL);
-
- FW_TRY
- {
- // FW_CAcquiredODFrame aqNewFrame = myDraft->AcquireFrame(ev, cloneInfo->fClonedFrameID);
- FW_CAcquiredODFrame aqNewFrame = toDraft->AcquireFrame(ev, cloneInfo->fClonedFrameID);
- FW_ASSERT(aqNewFrame != NULL);
-
- aqNewFrame->SetContainingFrame(ev, embeddingScopeFrame->GetODFrame(ev));
-
- FW_CAcquiredODShape aqFrameShape = aqNewFrame->AcquireFrameShape(ev, NULL);
-
- content->SingleEmbeddedFrameInternalized(ev,
- embeddingScopeFrame,
- aqNewPart,
- aqNewFrame,
- aqFrameShape,
- viewAs);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivPostInternalizePart
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingDataInterchange::PrivPostInternalizePart(Environment* ev,
- FW_CEmbeddingContent* content,
- FW_CCloneInfo* cloneInfo,
- ODTypeToken viewAs)
- {
- FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
- FW_ASSERT(cloneInfo->fClonedFrameID == kODNULLID);
-
- // ODDraft* myDraft = fPart->GetDraft(ev);
- // FW_CAcquiredODPart aqEmbeddedPart = myDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
- FW_CAcquiredODPart aqEmbeddedPart = cloneInfo->GetToDraft(ev)->AcquirePart(ev, cloneInfo->fClonedPartID);
-
- FW_CEmbeddingFrame* embeddingScopeFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
- FW_ASSERT(embeddingScopeFrame);
-
- content->SingleEmbeddedFrameInternalized(ev,
- embeddingScopeFrame,
- aqEmbeddedPart,
- NULL,
- cloneInfo->fFrameShape,
- viewAs);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivClonePart
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CEmbeddingDataInterchange::PrivClonePart(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- // ----- Clone the part -----
- cloneInfo->fClonedPartID = cloneInfo->Clone(ev, sourceSU->GetID(ev), 0, 0);
- FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
- result = FW_kInternalizePart;
-
- // ----- Look for the frame shape -----
- cloneInfo->fFrameShape = PrivReadFrameShape(ev, sourceSU);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivHandleEmbedAs
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CEmbeddingDataInterchange::PrivHandleEmbedAs(Environment* ev,
- FW_CContent* content,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo,
- ODPasteAsResult* embedAsInfo)
- {
- FW_ASSERT(FW_DYNAMIC_CAST(FW_CEmbeddingContent, content) != NULL);
-
- ODDraft* dstDraft = fPart->GetDraft(ev);
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- cloneInfo->BeginClone(ev, dstDraft);
-
- if (sourceSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
- result = DoInternalizeSingleEmbeddedFrame(ev, sourceSU, cloneInfo);
- else
- result = PrivClonePart(ev, sourceSU, cloneInfo);
-
- if (result == FW_kInternalizeFailed)
- {
- cloneInfo->AbortClone(ev);
- return result;
- }
-
- cloneInfo->EndClone(ev);
-
- PrivPostEmbedAs(ev, content, sourceSU, cloneInfo, embedAsInfo);
- PrivPostInternalizeData(ev, content, cloneInfo, result);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::PrivPostEmbedAs
- //----------------------------------------------------------------------------------------
- void FW_CEmbeddingDataInterchange::PrivPostEmbedAs( Environment* ev,
- FW_CContent* content,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo,
- ODPasteAsResult* embedAsInfo)
- {
- FW_UNUSED(sourceSU);
- FW_UNUSED(content);
-
- FW_ASSERT(FW_DYNAMIC_CAST(FW_CEmbeddingContent, content) != NULL);
-
- ODStorageUnit* newSU = NULL;
- FW_VOLATILE(newSU);
-
- FW_TRY
- {
- // ----- Acquire the newly embedded storage unit
- ODDraft* dstDraft = fPart->GetDraft(ev);
- newSU = dstDraft->AcquireStorageUnit(ev, cloneInfo->fClonedPartID);
-
- /*-- If user wants translation, do it before the part gets embedded --*/
- if (embedAsInfo->translateKind != NULL)
- {
- ODTranslateResult transResult = TranslateData(ev, newSU,
- embedAsInfo->selectedKind,
- embedAsInfo->translateKind);
- FW_ASSERT(transResult != kODCannotTranslate);
-
- //-- Translation was successful, save the preferred kind in the cloned SU
- ODSetISOStrProp(ev, newSU, kODPropPreferredKind, kODISOStr, embedAsInfo->selectedKind);
- }
-
- //-- Save the preferred editor in the cloned SU
- if (embedAsInfo->editor != kODNoEditor)
- {
- ODSetISOStrProp(ev, newSU, kODPropPreferredEditor, kODEditor, embedAsInfo->editor);
- }
-
- newSU->Release(ev);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (newSU)
- newSU->Release(ev);
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingDataInterchange::GetPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CEmbeddingDataInterchange::GetPresentation(Environment* ev, FW_CCloneInfo* cloneInfo)
- {
- return cloneInfo->GetScopeFrame(ev)->GetPresentation(ev);
- }
-